import requests
from lxml import etree
import zstandard as zstd
import json


import requests

cookies = {
    'cookie2': '123c31246e314f430351d0b15572e727',
    't': '59948a3ef0a5bc67923ae2702072d257',
    '_tb_token_': '3de7e94b9ee37',
    'mtop_partitioned_detect': '1',
    '_m_h5_tk': 'dae92daeffe2f612b07698fd3a564c31_1761989835069',
    '_m_h5_tk_enc': '9fa58c9530687628891f6023b1554e41',
    'thw': 'xx',
    'xlly_s': '1',
    'cna': 'A5qMIW0pPz8BASQJiUpHPGgo',
    'tfstk': 'gV-jbJxkxSVfQL8dlGkzRReWrvj6CYoEhR69KdE4BiIYXAOwah7O_qA15CRlWnS23Q19TQ1YbVf4fG96sCR6IxXO6Cd1_EurYKvcjGhF1DoenpMYFPd1kOBJeLX_M13PkjLKwnlETDork8IsGXJqUBd5e96dXtQOBzH53tBAXNBveY6OQSUTDCp-F_Xd6PEOX0ERnOPOXGdO2Y6OKGC96ZHWe_XOX1hcTWWsQs9jK8zFj0GrKK17XlK5effBh7rAK3BbL1vfNfipVlQf9KC7XjtxRM11ZHhrPLAykIWk1DG52pL5DtOtvy5JPLKc8MgLlBpyiHsvAjZVUN1XynQ7BlpRqs7J5IGbosL2NwXRyRihUB5JnnLSI7pvTssAeaoKdLQ9znbH0bEfvevV0Fd-VoOd4WrFOtxg58_3fT1EFYagS-BeXXnhSQCFkTXfVYM7GgQAET1EFYagSZBlUzMSFSsR.',
    'isg': 'BO_vtE6x2mNhN95fXakh3yYlfgP5lEO2PeE6KAF84d5lUA9SCWedBh0G0kDuLRsu',
}

headers = {
    'accept': '*/*',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cache-control': 'no-cache',
    'pragma': 'no-cache',
    'referer': 'https://uland.taobao.com/',
    'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'script',
    'sec-fetch-mode': 'no-cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
    # 'cookie': 'cookie2=123c31246e314f430351d0b15572e727; t=59948a3ef0a5bc67923ae2702072d257; _tb_token_=3de7e94b9ee37; mtop_partitioned_detect=1; _m_h5_tk=dae92daeffe2f612b07698fd3a564c31_1761989835069; _m_h5_tk_enc=9fa58c9530687628891f6023b1554e41; thw=xx; xlly_s=1; cna=A5qMIW0pPz8BASQJiUpHPGgo; tfstk=gV-jbJxkxSVfQL8dlGkzRReWrvj6CYoEhR69KdE4BiIYXAOwah7O_qA15CRlWnS23Q19TQ1YbVf4fG96sCR6IxXO6Cd1_EurYKvcjGhF1DoenpMYFPd1kOBJeLX_M13PkjLKwnlETDork8IsGXJqUBd5e96dXtQOBzH53tBAXNBveY6OQSUTDCp-F_Xd6PEOX0ERnOPOXGdO2Y6OKGC96ZHWe_XOX1hcTWWsQs9jK8zFj0GrKK17XlK5effBh7rAK3BbL1vfNfipVlQf9KC7XjtxRM11ZHhrPLAykIWk1DG52pL5DtOtvy5JPLKc8MgLlBpyiHsvAjZVUN1XynQ7BlpRqs7J5IGbosL2NwXRyRihUB5JnnLSI7pvTssAeaoKdLQ9znbH0bEfvevV0Fd-VoOd4WrFOtxg58_3fT1EFYagS-BeXXnhSQCFkTXfVYM7GgQAET1EFYagSZBlUzMSFSsR.; isg=BO_vtE6x2mNhN95fXakh3yYlfgP5lEO2PeE6KAF84d5lUA9SCWedBh0G0kDuLRsu',
}

params = {
    'jsv': '2.7.2',
    'appKey': '12574478',
    't': '1761979439716',
    'sign': '7ccb7c18d4ce60546e85b7bce4cdbc52',
    'api': 'mtop.relationrecommend.wirelessrecommend.recommend',
    'v': '2.0',
    'type': 'jsonp',
    'dataType': 'jsonp',
    'callback': 'mtopjsonp4',
    'data': '{"appId":"43356","params":"{\\"device\\":\\"HMA-AL00\\",\\"isBeta\\":\\"false\\",\\"grayHair\\":\\"false\\",\\"from\\":\\"nt_history\\",\\"brand\\":\\"HUAWEI\\",\\"info\\":\\"wifi\\",\\"index\\":\\"4\\",\\"rainbow\\":\\"\\",\\"schemaType\\":\\"auction\\",\\"elderHome\\":\\"false\\",\\"isEnterSrpSearch\\":\\"true\\",\\"newSearch\\":\\"false\\",\\"network\\":\\"wifi\\",\\"subtype\\":\\"\\",\\"hasPreposeFilter\\":\\"false\\",\\"prepositionVersion\\":\\"v2\\",\\"client_os\\":\\"Android\\",\\"gpsEnabled\\":\\"false\\",\\"searchDoorFrom\\":\\"srp\\",\\"debug_rerankNewOpenCard\\":\\"false\\",\\"homePageVersion\\":\\"v7\\",\\"searchElderHomeOpen\\":\\"false\\",\\"search_action\\":\\"initiative\\",\\"sugg\\":\\"_4_1\\",\\"sversion\\":\\"13.6\\",\\"style\\":\\"list\\",\\"ttid\\":\\"600000@taobao_pc_10.7.0\\",\\"needTabs\\":\\"true\\",\\"areaCode\\":\\"CN\\",\\"vm\\":\\"nw\\",\\"countryNum\\":\\"156\\",\\"m\\":\\"pc_sem\\",\\"page\\":\\"1\\",\\"n\\":48,\\"q\\":\\"%E9%B1%BC%E7%AB%BF\\",\\"qSource\\":\\"url\\",\\"pageSource\\":\\"tbpc.pc_sem_alimama/a.search_manual.0\\",\\"tab\\":\\"all\\",\\"pageSize\\":48,\\"totalPage\\":100,\\"totalResults\\":4800,\\"sourceS\\":\\"0\\",\\"sort\\":\\"_coefp\\",\\"bcoffset\\":\\"\\",\\"ntoffset\\":\\"\\",\\"filterTag\\":\\"\\",\\"service\\":\\"\\",\\"prop\\":\\"\\",\\"loc\\":\\"\\",\\"start_price\\":null,\\"end_price\\":null,\\"startPrice\\":null,\\"endPrice\\":null,\\"itemIds\\":null,\\"p4pIds\\":null,\\"categoryp\\":\\"\\",\\"myCNA\\":\\"A5qMIW0pPz8BASQJiUpHPGgo\\",\\"clk1\\":\\"03bf749cb9c713decfde08ccd1ec7d1f\\",\\"refpid\\":\\"mm_26632258_3504122_32538762\\"}"}',
}

response = requests.get(
    'https://h5api.m.taobao.com/h5/mtop.relationrecommend.wirelessrecommend.recommend/2.0/',
    params=params,
    cookies=cookies,
    headers=headers,
)

print(type(response.text))
response_json = json.loads(response.text)
print(type(response_json))

# 解压zstd压缩的内容
# decompressor = zstd.ZstdDecompressor()
# with decompressor.stream_reader(response.content) as reader:
#     decompressed_data = reader.read()
#
# print(decompressed_data)

# json_data = json.loads(decompressed_data.decode('utf-8'))
# print(json_data)